package com.gdth.bank.presenter;

import java.util.List;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import com.gdth.bank.model.MediaModel;
import com.gdth.bank.view.MediaView;
import com.gdth.database.bean.TAppMedia;

/** 
 * @author  Arvin: 
 * @version 2016年5月27日 上午10:30:42 
 * 
 */
public class MediaPresenter {
	private MediaView mMediaView;
	private MediaModel mMediaModel;
	
	public MediaPresenter(MediaView mMediaView){
		this.mMediaView = mMediaView;
		this.mMediaModel = new MediaModel();
	}
	
	public void saveMedia(TAppMedia mMedia){
		mMediaView.showProgressDialog();
		mMediaModel.save(mMedia)
			.subscribeOn(Schedulers.io())
			.observeOn(AndroidSchedulers.mainThread())
			.subscribe(new Subscriber<TAppMedia>(){

				@Override
				public void onCompleted() {
					// TODO Auto-generated method stub
					mMediaView.hideProgressDialog();
				}

				@Override
				public void onError(Throwable arg0) {
					// TODO Auto-generated method stub
					mMediaView.hideProgressDialog();
				}

				@Override
				public void onNext(TAppMedia arg0) {
					// TODO Auto-generated method stub
					mMediaView.updateView(1, arg0);
				}});
	}

	public void getAll() {
		mMediaView.showProgressDialog();
		mMediaModel.getAllMedia()
			.subscribeOn(Schedulers.io())
			.observeOn(AndroidSchedulers.mainThread())
			.subscribe(new Subscriber<List<TAppMedia>>(){

				@Override
				public void onCompleted() {
					// TODO Auto-generated method stub
					mMediaView.hideProgressDialog();
				}

				@Override
				public void onError(Throwable arg0) {
					// TODO Auto-generated method stub
					mMediaView.hideProgressDialog();
				}

				@Override
				public void onNext(List<TAppMedia> arg0) {
					// TODO Auto-generated method stub
					mMediaView.updateView(1, arg0);
				}
				
			});
	}
	
}
